
import { merge } from 'lodash'
import io from '@/utils/http/index.js'

const state = {
  // undefined 加载中 null 未登录
  userInfo: undefined
}

const actions = {
  getUserInfo ({ commit, state, dispatch }, payload) {
    return new Promise((resolve, reject) => {
      io({
        url: '/show/user/info'
      }).then(res => {
        if (res.data) {
          commit('setParams', { userInfo: res.data })
        } else {
          commit('setParams', {userInfo: null})
        }
        resolve(res)
      }).catch(e => {
        commit('setParams', {userInfo: null})
        reject(e)
      })
    })
  }
}

const getters = {
  
}

const mutations = {
  /**
   * 设置参数
   * */
   setParams (state, payload) {
    state = merge(state, payload)
  }
}

export default {
  strict: true,
  namespaced: true,
  state,
  getters,
  mutations,
  actions
}